using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BirdSoundsControl : MonoBehaviour
{
    [SerializeField]
    private AudioSource[] audioSource;
    private Dictionary<string, AudioClip> clips;
    void Start()
    {
        audioSource=new AudioSource[3];

        clips = new Dictionary<string, AudioClip>();
        AssetBundle ab = ABManger.LoadFromFile("sounds");
        AudioClip[] temps=ab.LoadAllAssets<AudioClip>();
        foreach(AudioClip clip in temps)
        {
            clips.Add(clip.name, clip);
            Debug.Log(clip.name);
        }
        BirdControl birdControl=GetComponent<BirdControl>();
        if (birdControl != null)
        {
            birdControl.onDie += PlayDieSound;
            birdControl.onFly+=PlayFlySound;
            birdControl.onScored += PlayGetScoredSound;
        }
        Debug.Log(audioSource[0] == null);
        audioSource[0]=gameObject.AddComponent<AudioSource>();
        audioSource[0].clip = clips["death"];
        audioSource[1] = gameObject.AddComponent<AudioSource>();
        audioSource[1].clip = clips["fly"];
        audioSource[2] = gameObject.AddComponent<AudioSource>();
        audioSource[2].clip = clips["scored"];
    }
    void PlayDieSound()
    {
        
        audioSource[0].Play();
    }
    void PlayFlySound()
    {
        
        audioSource[1].Play();
    }
    void PlayGetScoredSound()
    {
       
        audioSource[2].Play();
    }

    
}
